<template>
  <div>
    <h3 style="text-align: center">流量告警类型</h3>
    <div id="WarningChart" style="width:90%;height:300px;"></div>
  </div>
</template>

<script>
export default {
  name: 'WarningChart',
  data () {
    return {
      myChart: null,
      userAlarmData:[]
    }
  },
  created() {
    this.$Pubsub.subscribe('userAlarmData',(msgName,msg)=>{
      this.userAlarmData = msg
      console.log(this.userAlarmData)
      this.chartInit();
    })
  },
  methods: {
    chartInit () {
      // if (this.myChart !== null) {
      //   this.myChart.dispose()
      // }
      this.myChart = this.$echarts.init(document.getElementById('WarningChart'))
      let option = {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          orient: 'vertical',
          right: '1%',
          top: '18%',
          data: this.userAlarmData[1]
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: '60%',
            center: ['50%', '40%'],
            data:this.userAlarmData[0],
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
      this.myChart.setOption(option)
    }
  }
}
</script>

<style scoped>

</style>
